package com.sky.controller.user;

import com.sky.dto.*;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import lombok.extern.slf4j.Slf4j;
import org.apache.poi.hssf.dev.ReSave;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author hyh
 * @version 1.0
 */
@RestController
@RequestMapping("/user/order")
@Slf4j
@Api(tags = "订单接口")
public class OrderController {
    @Autowired
    OrderService orderService;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> OrderSubmit(@RequestBody OrdersSubmitDTO ordersSubmitDTO){
        log.info("发送订单{}",ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO = orderService.submit(ordersSubmitDTO);
        return  Result.success(orderSubmitVO);
    }

    /**
     * 订单支付
     *
     * @param ordersPaymentDTO
     * @return
     */
    @PutMapping("/payment")
    @ApiOperation("订单支付")
    public Result<String> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        String orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }


    @ApiOperation("订单的分页查询")
    @GetMapping("/historyOrders")
    public Result<PageResult> OrdersPage(OrdersPageQueryDTO ordersPageQueryDTO){
        log.info("订单的分页查询{}",ordersPageQueryDTO);
        PageResult result = orderService.pageSelect(ordersPageQueryDTO);
        return Result.success(result);
    }
    @ApiOperation("订单详情")
    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> OrderDetail(@PathVariable Integer id){
        log.info("查询订单详情{}",id);
        OrderVO orderVO = orderService.selectDetail(id);
        return Result.success(orderVO);
    }
    @ApiOperation("取消订单")
    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Integer id){
        log.info("取消订单{}",id);
        OrdersRejectionDTO ordersRejectionDTO = new OrdersRejectionDTO();
        ordersRejectionDTO.setId(id.longValue());
        orderService.cancel(ordersRejectionDTO);
        return Result.success();
    }

    @ApiOperation("再来一单")
    @PostMapping("/repetition/{id}")
    public Result againOrder(@PathVariable Integer id){
        log.info("再来一单{}",id);
        return Result.success();
    }
    @GetMapping("/reminder/{id}")
    public Result Reminders(@PathVariable Long id){
        log.info("用户{}催单",id);
        orderService.Reminders(id);
        return Result.success();
    }



}
